<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
import util from "@/libs/util";
import { mapActions } from 'vuex'
export default {
  name: "app",
  watch: {
    "$i18n.locale": "i18nHandle",
    $route(to, from) {
      if(to.path=='/index'&&from.path=='/login'){
        this.closeAll()
      }
    }
  },
  created() {
    this.i18nHandle(this.$i18n.locale);

    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload", () => {
      sessionStorage.setItem(
        "lry",
        JSON.stringify(this.$store.getters.usernameL)
      );
    });
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("lry")) {
      this.$store.commit(
        "user/SET_NAME",
        JSON.parse(sessionStorage.getItem("lry"))
      );
    }
  },
  
  methods: {
    ...mapActions('d2admin/page', ['closeAll']),
    i18nHandle(val, oldVal) {
      util.cookies.set("lang", val);
      document.querySelector("html").setAttribute("lang", val);
    }
  }
};
</script>

<style lang="scss">
@import "~@/assets/style/public-class.scss";
</style>
